﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL;
using Models;

namespace Player.Admin
{
    public partial class gmtype : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                //刷新表
                rpt_gmtyptSX();
                //修改信息框展示
                if (Request.QueryString["upid"] != null)
                {
                    this.pl_add.Visible = false;
                    this.Pl_update.Visible = true;
                    int id = Convert.ToInt32(Request.QueryString["upid"]);
                    this.lbl_pl2gtid.Text = id.ToString();
                    List<GmType> ls = BLL.GmTypeManage.SeleIdGmType(id);
                    this.txt_pl2name.Text = ls[0].Gt_Name.ToString();
                }
                //删除提示
                if (Request.QueryString["deid"] != null)
                {
                    this.pl_delete.Visible = true;
                }
            }

            

        }

        //刷新表
        private void rpt_gmtyptSX()
        {
            this.rpt_gmtype.DataSource = BLL.GmTypeManage.SeleAllGmType();
            this.rpt_gmtype.DataBind();
        }

        //添加信息框显示
        protected void btn_add_Click(object sender, EventArgs e)
        {
            this.Pl_update.Visible = false;
            this.pl_add.Visible = true;
        }

        //添加信息框隐藏
        protected void btn_plgb_Click(object sender, EventArgs e)
        {
            this.pl_add.Visible = false;
        }

        //保存添加信息
        protected void txt_plctrls_Click(object sender, EventArgs e)
        {
            //获取输入内容保存至
            GmType gt = new GmType();
            gt.Gt_Name=this.txt_plname.Text.Trim();
            //执行添加
            bool bl = BLL.GmTypeManage.AddGmType(gt);
            if (bl)
            {
                this.lbl_plbcts.Text = "保存成功";
                //刷新表
                rpt_gmtyptSX();
            }
            else
            {
                this.lbl_plbcts.Text = "保存失败";
            }
        }

        //保存修改信息
        protected void btn_pl2bc_Click(object sender, EventArgs e)
        {
            //获取内容保存至
            GmType gt = new GmType();
            gt.Gt_Name = this.txt_pl2name.Text.Trim();
            gt.Gt_Id= Convert.ToInt32(this.lbl_pl2gtid.Text.Trim());
            //修改
            bool bl = BLL.GmTypeManage.UpdaGmType(gt);
            if (bl)
            {
                this.lbl_pl2bcts.Text = "保存成功";
                //刷新表
                rpt_gmtyptSX();
            }
            else
            {
                this.lbl_pl2bcts.Text = "保存失败";
            }
        }

        //修改信息框隐藏
        protected void btn_pl2gb_Click(object sender, EventArgs e)
        {
            this.Pl_update.Visible = false;
        }

        //确定删除
        protected void btn_delequedin_Click(object sender, EventArgs e)
        {
            int id = Convert.ToInt32(Request.QueryString["deid"]);
            bool bl = BLL.GmTypeManage.DeleGmType(id);
            if (bl)
            {
                this.pl_delete.Visible = false;
                //刷新表信息
                rpt_gmtyptSX();
            }
        }

        //取消删除
        protected void btn_delequxiao_Click(object sender, EventArgs e)
        {
            this.pl_delete.Visible = false;
        }

        //刷新
        protected void imgbtnsx_Click(object sender, ImageClickEventArgs e)
        {
            rpt_gmtyptSX();
        }

        //查询
        protected void imgbtn_Click(object sender, ImageClickEventArgs e)
        {
            //获取输入内容
            string name = this.txt_name.Text.Trim();
            //判断是否输入
            if (name=="")
            {
                this.lbl_ChaXunTiShi.Text = "请输入查询内容";
                this.img_weizhaodao.Visible = true;
                return;
            }
            //查询
            List<GmType> ls = BLL.GmTypeManage.SelenameGmType(name);
            //没有查询结果
            if (ls.Count==0)
            {
                this.lbl_ChaXunTiShi.Text = "未找到相关内容";
                this.img_weizhaodao.Visible = true;
                return;
            }
            this.lbl_ChaXunTiShi.Text = "";
            this.img_weizhaodao.Visible = false;
            this.rpt_gmtype.DataSource = ls;
            this.rpt_gmtype.DataBind();
        }
    }
}